Imports BusinessLayer
Imports EntityLayer

Partial Class ListaProductoProveedor
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Call ListarProductoProveedor()
        End If
    End Sub

    Private Sub ListarProductoProveedor()
        dgDatos.DataSource = ProductoProveedorBL.ListarTodo
        dgDatos.DataBind()
    End Sub

    Protected Sub btnNuevo_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Response.Redirect("ProductoProveedor.aspx")
    End Sub

    Private Sub MostrarProductos(ByVal strCodigo As String)
        lblProducto.Text = "Productos del Proveedor "
        dgListaProducto.DataSource = ProductoProveedorBL.ListarxCodigo(strCodigo)
        dgListaProducto.DataBind()
    End Sub

    Private Sub EliminarSolicitud(ByVal strCodigo As String)
        ProductoProveedorBL.Eliminar(strCodigo)
        dgDatos.DataSource = ProductoProveedorBL.ListarTodo
        dgDatos.DataBind()
        MostrarProductos("")
    End Sub

    Private Sub EditarSolicitud(ByVal strCodigo As String)
        Response.Redirect("ProductoProveedor.aspx?strCodigo=" & strCodigo)
    End Sub

    Protected Sub dgDatos_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles dgDatos.RowCommand
        Try
            Dim index As Integer = Integer.Parse(e.CommandArgument.ToString())
            Dim row As GridViewRow = dgDatos.Rows(index)
            Dim key As DataKey = dgDatos.DataKeys(row.RowIndex)


            If e.CommandName = "Prod" Then
                MostrarProductos((key(0).ToString()))
            End If
            If e.CommandName = "Edt" Then
                EditarSolicitud((key(0).ToString()))
            End If
            If e.CommandName = "Del" Then
                EliminarSolicitud((key(0).ToString()))
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class
